package com.company.cloud.goodsrestservice.service.impl;

import com.company.cloud.goodsrestservice.core.AbstractService;
import com.company.cloud.goodsrestservice.dao.BrandMapper;
import com.company.cloud.goodsrestservice.model.Brand;
import com.company.cloud.goodsrestservice.service.BrandService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


/**
 * Created by reabout on 2018/03/24.
 */
@Service
@Transactional
public class BrandServiceImpl extends AbstractService<Brand> implements BrandService {
    @Resource
    private BrandMapper brandMapper;

    private final Logger log = LoggerFactory.getLogger(BrandService.class);

    public Brand chkInsert(String brandName) {
        Brand brand = findBy("brandName", brandName);
        if (brand == null & brandName != "") {
            log.info("New brand {}", brandName);
            brand = new Brand();
            brand.setBrandName(brandName);
            brand.setBrandMark("");
            brand.setStatus(2);
            brand.setCreateTime(System.currentTimeMillis());
            save(brand);
            brand = findBy("brandName", brandName);
        }
        return brand;
    }
}
